﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using LCTMoodle.Service;

namespace LCTMoodle.Models.ViewModels
{
    public class BaiVietViewModel : Model
    {
        public int ma { get; set; }
        public int maKhoaHoc { get; set; }
        public string tenKhoaHoc { get; set; }
        public int maNguoiTao { get; set; }
        public string tenNguoiTao { get; set; }
        public string tieuDe { get; set; }
        public string noiDung { get; set; }
        public DateTime thoiGian { get; set; }
        public int maTapTin { get; set; }
        public string nhomBaiViet { get; set; }
        public List<LoaiBaiVietViewModel> loaiBaiViet { get; set; }
        public int thuTu { get; set; }

        public override void assignModel(SqlDataReader dr)
        {
            for (int i = 0; i < dr.FieldCount; i++)
            {
                switch (dr.GetName(i))
                {
                    case "Ma": 
                        ma = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "MaKhoaHoc": 
                        maKhoaHoc = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "TenKhoaHoc": 
                        tenKhoaHoc = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "MaNguoiTao": 
                        maNguoiTao = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "TenNguoiTao": 
                        tenNguoiTao = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "TieuDe": 
                        tieuDe = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "NoiDung": 
                        noiDung = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "ThoiGian": 
                        thoiGian = (dr.IsDBNull(i)) ? DateTime.MinValue : dr.GetDateTime(i); break;
                    case "MaTapTin": 
                        maTapTin = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    case "NhomBaiViet": 
                        noiDung = (dr.IsDBNull(i)) ? null : dr.GetString(i); break;
                    case "LoaiBaiViet":
                        loaiBaiViet = (dr.IsDBNull(i)) ? null : LoaiBaiVietService.layLoaiBaiVietTheoMaBaiViet(this.ma); break;
                    case "ThuTu":
                        thuTu = (dr.IsDBNull(i)) ? 0 : dr.GetInt32(i); break;
                    default: 
                        break;
                }
            }
        }
    }
}